//
//  HDItemVC.m
//  HDWuDaDaoServiceCenter
//
//  Created by HDNiuKuiming on 2017/4/7.
//  Copyright © 2017年 HDNiuKuiming. All rights reserved.
//

#import "HDItemVC.h"
#import "NavigationTitleView.h"

@interface HDItemVC ()
@property (nonatomic, strong) NavigationTitleView *myTitleLabel;

@end


@implementation HDItemVC

#pragma mark
#pragma mark -------- Init Methods --------

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self naviBtnInit];
}

- (void)naviBtnInit
{
//    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    leftButton.frame = CGRectMake(5, 15, 40, 48);
//    leftButton.imageView.contentMode = UIViewContentModeScaleToFill;
//    [leftButton setImage:[UIImage imageNamed:@"navi_back"] forState:UIControlStateNormal];
//    [leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *leftBarButtonItem =[[UIBarButtonItem alloc]initWithCustomView:leftButton];
//    [self.navigationItem setLeftBarButtonItem:leftBarButtonItem];
//    
//    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    rightButton.frame = CGRectMake(0, 0.0, 27, 27);
//    [rightButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
//    UIBarButtonItem *rightBarButtonItem =[[UIBarButtonItem alloc]initWithCustomView:rightButton];
//    [self.navigationItem setRightBarButtonItem:rightBarButtonItem];
//    [self titleLabeInit];
//    
//    NSString *barImageName = @"navi_bar";
//    if (self.view.frame.size.width == 375)
//        barImageName = @"navi_bar_6";
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:barImageName] forBarMetrics:UIBarMetricsDefault];
}

- (void)setTitle:(NSString *)title
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [self titleLabeInit];
        NSString *myTitle = title;
        if (title.length == 0)
            myTitle = @" ";
        _myTitleLabel.titleName = myTitle;
        _myTitleLabel.frame = CGRectMake(50, 0, ScreenWidth-100, 44);
        _myTitleLabel.titleFont = [UIFont fontWithName:@"FZQKBYSJW--GB1-0" size:22.0];
        _myTitleLabel.titleColor = [UIColor blackColor];
        _myTitleLabel.backgroundColor = [UIColor clearColor];
        NSLog(@" frame is %@", [NSValue valueWithCGRect:_myTitleLabel.frame]);
        
    });
}

- (void)titleLabeInit
{
    [self titleRelease];
    _myTitleLabel = [[NavigationTitleView alloc]init];
    _myTitleLabel.frame = CGRectMake(50, 0, ScreenWidth-100, 44);
    _myTitleLabel.titleName = @"  ";
    
    self.navigationItem.titleView = _myTitleLabel;
}

- (void)titleRelease
{
    [_myTitleLabel removeFromSuperview];
    self.myTitleLabel = nil;
}

- (void)back
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [self titleRelease];
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    NSMutableDictionary *attributes= [[NSMutableDictionary alloc] init];
    [attributes setValue:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    [attributes setValue:[UIColor clearColor] forKey:NSBackgroundColorAttributeName];
    [self.navigationController.navigationBar setTitleTextAttributes:attributes];
    
    NSString *barImageName = @"navi_bar";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:barImageName] forBarMetrics:UIBarMetricsDefault];
    
    //[MobClick beginLogPageView:self.description];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [[HDDeclare sharedDeclare] setVisibleVC:self.navigationController.visibleViewController];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[HDDeclare sharedDeclare] setVisibleVC:nil];
    //[MobClick endLogPageView:self.description];
    
}

#pragma mark
#pragma mark -------- Rotate Action --------

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

-(BOOL)shouldAutorotate
{ return NO;}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
